package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.CFacility;
import com.ruoyi.wechat.domain.CFacilityType;
import com.ruoyi.wechat.domain.WxCampFacilityVo;
import com.ruoyi.wechat.service.IWxCFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;
@RestController
@RequestMapping("/wechat/facility")
public class WxCFacilityController extends BaseController {

    @Autowired
    private IWxCFacilityService wxCFacilityService;

//    @GetMapping("/list")
//    public AjaxResult list()
//    {
//        List<CFacilityType> list = wxCFacilityService.FList();
//        return success(list);
//    }
@GetMapping("/list")
public TableDataInfo list(CFacilityType cFacilityType)
{
    List<CFacilityType> list = wxCFacilityService.selectCFacilityByFacilityTypeId(cFacilityType);
    System.out.println("返回值"+list);
    return getDataTable(list);
}

    @GetMapping(value = "/getInfo/{facilityId}")
    public AjaxResult getInfo(@PathVariable("facilityId") String facilityId)
    {
        if (facilityId == null){
            return error("您的营地Id不能为空");
        }
        return success(wxCFacilityService.selectCFacilityByFacilityId(facilityId));
    }
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxCampFacilityVo wxCampFacilityVo){
        if (wxCampFacilityVo.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxCampFacilityVo.getFacilityIds() == null) {
            return error("服务设施Id不能为空");
        }
        return toAjax(wxCFacilityService.insertCFacility(wxCampFacilityVo.getCampId(), wxCampFacilityVo.getFacilityIds()));
    }
}
